package com.ihome.excel.xlsx.engine.imports;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;

import com.ihome.excel.xlsx.entity.EncapsulationEnum;
import com.ihome.excel.xlsx.entity.TemplateConfig;
import com.ihome.excel.xlsx.validate.ICellsValidateRule;
import com.ihome.excel.xlsx.validate.IRowsValidateRule;
import com.ihome.excel.xlsx.validate.impl.DefaultValidateRule;

@SuppressWarnings("all")
public class ExcelParserEngine {

    private TempateParseEngine templateEngine = new TempateParseEngine();

    private SheetParseEngine dataAssembly = new SheetParseEngine();
    
    /**
     * 流式无验证器接口
     * @param inputStream
     * @return
     */
    public List getResultAsInpuStream(InputStream inputStream) {
        return getResultAsInpuStream(inputStream, null,null);
    }
    
    /**
     * 流式行级验证器接口
     * @param inputStream
     * @param rowValidateRule
     * @return
     */
    public List getResultAsInpuStream(InputStream inputStream,IRowsValidateRule rowValidateRule){
        return getResultAsInpuStream(inputStream,null,rowValidateRule);
    }
    
    /**
     * 流式列级验证器接口
     * @param inputStream
     * @param validateRule
     * @return
     */
    public List getResultAsInpuStream(InputStream inputStream, ICellsValidateRule validateRule) {
        return getResultAsInpuStream(inputStream, validateRule, null);
    }
    
    /**
     * 流式行级,列级验证器接口
     * @param inputStream
     * @param validateRule
     * @param rowValidateRule
     * @return
     */
    public List getResultAsInpuStream(InputStream inputStream, ICellsValidateRule validateRule, IRowsValidateRule rowValidateRule) {
        Workbook workBook = StreamingReader.builder().open(inputStream);
        TemplateConfig config = templateEngine.getTemplateConfig(workBook);
        return dataAssembly.getParserList(workBook, config, validateRule, rowValidateRule);
    }
    
    
    /**
     * 文件无验证器接口
     * @param filePath
     * @return
     */
    public List getResultAsFilePath(String filePath) {
        return getResultAsFilePath(filePath, null, null);
    }
    
    /**
     * 文件行级验证器接口
     * @param filePath
     * @param rowValidateRule
     * @return
     */
    public List getResultAsFilePath(String filePath, IRowsValidateRule rowValidateRule) {
        return getResultAsFilePath(filePath, null, rowValidateRule);
    }
    
    /**
     * 文件列级验证器接口
     * @param filePath
     * @param validateRule
     * @return
     */
    public List getResultAsFilePath(String filePath, ICellsValidateRule validateRule) {
        return getResultAsFilePath(filePath, validateRule, null);
    }
    
    /**
     * 文件行级,列级验证器接口
     * @param filePath
     * @param validateRule
     * @param rowValidateRule
     * @return
     */
    public List getResultAsFilePath(String filePath, ICellsValidateRule validateRule, IRowsValidateRule rowValidateRule) {
        Workbook workBook = StreamingReader.builder().open(new File(filePath));
        TemplateConfig config = templateEngine.getTemplateConfig(workBook);
        return dataAssembly.getParserList(workBook, config, validateRule, rowValidateRule);
    }
}
